package com.qiangzhi.mapper;

import com.github.pagehelper.Page;
import com.qiangzhi.annotation.AutoFill;
import com.qiangzhi.pojo.dto.CollegeDTO;
import com.qiangzhi.pojo.dto.CollegePageQueryDTO;
import com.qiangzhi.enums.OperationType;
import com.qiangzhi.pojo.po.CollegePO;
import com.qiangzhi.pojo.vo.CollegeVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface CollegeMapper {

    /**
     * 新增学院和班级
     *
     * @param collegePO
     * @return
     */
    @AutoFill(value = OperationType.INSERT)
    void insertCollegeOrMajor(CollegePO collegePO);

    /**
     * 根据id编辑学院和班级信息
     *
     * @param collegePO
     * @return
     */
    @AutoFill(value = OperationType.UPDATE)
    void updateCollegeOrMajor(CollegePO collegePO);

    /**
     * 学院和班级分页查询
     *
     * @param collegePageQueryDTO
     * @return
     */
    Page<CollegeVO> page(CollegePageQueryDTO collegePageQueryDTO);

    /**
     * 查询全部学院
     *
     * @return
     */
    @Select("select id,college from tb_college order by create_time desc")
    List<CollegeVO> getAllCollege();

    /**
     * 根据学院id查询班级
     *
     * @param collegeId
     * @return
     */
    @Select("select id,major from tb_major where college_id = #{collegeId} order by create_time desc")
    List<CollegeVO> getMajorByCollegeId(Integer collegeId);

    /**
     * 根据id查询学院或班级详细信息
     *
     * @param collegeDTO
     * @return
     */
    CollegeVO getDetail(CollegeDTO collegeDTO);

    /**
     * 根据id删除学院信息
     *
     * @param collegeId
     * @return
     */
    @Delete("delete from tb_college where id = #{collegeId}")
    void deleteByCollegeId(Integer collegeId);

    /**
     * 根据id删除班级信息
     *
     * @param majorId
     * @return
     */
    @Delete("delete from tb_major where id = #{majorId}")
    void deleteByMajorId(Integer majorId);

    /**
     * 检查班级表是否有学院数据绑定
     *
     * @param collegeId
     * @return
     */
    @Select("select count(college_id) from tb_major where college_id = #{collegeId}")
    Integer checkCollegeLink(Integer collegeId);

    /**
     * 检查学生表是否有班级数据绑定
     *
     * @param majorId
     * @return
     */
    @Select("select count(major_id) from sd_info where major_id = #{majorId}")
    Integer checkMajorLink(Integer majorId);

}
